<template>
    <div>
        <div>{{isLoading ? '加载中' : result}}</div>
        <weui-button type="primary" :is_mini="true" v-for="item in failedUsernames" v-bind:key="item" v-show="!isLoading" @on-click="on_refresh_click(item)">
            刷新{{item}}
        </weui-button>
    </div>
</template>
<script>
import global from '../lib/global'
import axios from 'axios'
import WeuiButton from '../vue2componentSet/src/components/WeuiButton'

export default {
    components: {
        WeuiButton
    },
    data() {
        return {
            result: '',
            isLoading: false,
            failedUsernames: []
        }
    },
    mounted() {
        this.$store.commit('set_title', '获取淘宝订单')

        if (!this.$store.state.admin) {
            this.$router.goback()
            return
        }

        this.getTaobaoBill()
    },
    methods: {
        getTaobaoBill() {
            this.isLoading = true
            axios.post(global.server + 'getTaobaoBill.do', {}).then(result => {
                this.isLoading = false
                const obj = result.data
                if (obj.result == 1) {
                    this.result = obj.successCnt + '个成功，' + obj.failedCnt + '个失败'
                    this.failedUsernames = obj.failedUsernames
                } else {
                    this.result = '失败'
                }
            }, result => {
                this.isLoading = false
                this.result = '访问异常'
            })
        },
        on_refresh_click() {
            this.getTaobaoBill()
        }
    }
}
</script>
